package com.tangji.signaltower.service.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.TimeUtils;
import com.tangji.signaltower.service.dao.inter.MockBinaryTradeDao;
import com.tangji.signaltower.service.dao.entity.MockBinaryTradeEntity;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: anonymous
 * Date: 2020-09-17
 * Time: 23:43:29.173
 */

@Repository
public class MockBinaryTradeDaoImpl extends AbstractBaseMapper<MockBinaryTradeEntity> implements MockBinaryTradeDao {

    @Override
    public List<MockBinaryTradeEntity> getListByStatus(Integer status) {
        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        return getSqlSession().selectList(getStatement("getListByStatus"), params);
    }

    @Override
    public List<MockBinaryTradeEntity> getLatestByUserCodesAndStatusAndTime(List<String> userCodes, Integer status) {
        if (CollectionUtils.isEmpty(userCodes)) {
            return null;
        }

        long startTimeL = System.currentTimeMillis() - 1000 * 180;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String startTime = sdf.format(new Date(Long.parseLong(String.valueOf(startTimeL))));


        Map<String, Object> params = new HashMap<>();
        params.put("status", status);
        params.put("userCodes", userCodes);
        params.put("startTime", startTime);

        return getSqlSession().selectList(getStatement("getLatestByUserCodesAndStatusAndTime"), params);
    }

    public static void main(String[] args) {


        long startTimeL = System.currentTimeMillis() - 1000 * 1800;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String startTime = sdf.format(new Date(Long.parseLong(String.valueOf(startTimeL))));

        System.err.println(startTime);
    }
}